package com.itqf.controller;

import com.itqf.entity.TbItem;
import com.itqf.service.TbItemService;
import com.itqf.utils.R;
import com.itqf.vo.QueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/17
 * @Time: 下午4:56
 */
@Controller
@Api(value = "商品",description = "处理商品信息的接口的api",produces = "application/json")
public class TbItemController {

    @Autowired //  springmvc是spring的子容器  springmvc可以直接访问Spring工厂中的对象
    private TbItemService tbItemService;

    @ApiOperation(value = "全查",httpMethod = "GET")
    @RequestMapping(value="/findAll",method=RequestMethod.GET)
    @ResponseBody
    public List<TbItem> findAll(){

        return  tbItemService.findAll();
    }

    ///@RequestMapping(value="/add",method=RequestMethod.POST)
    @ApiOperation(value = "新增",httpMethod = "POST")
    @PostMapping("/add")
    @ResponseBody
    public R insert(@RequestBody TbItem item){

        return tbItemService.add(item);
    }

    //http://localhost:8080/findAll?sort=price&order=desc&limit=10&offset=0
    //limit=10&offset=0   limit：每页显示多少条   offset：起始记录
    //{"id":11,"search":"sss"}  @RequestBody
    //接口url /findByPage
    //接口参数：limit offset...
    //响应： {total:100,rows:[{},{}]}

    @GetMapping("/findByPage")
    @ResponseBody //响应
    @ApiOperation(value = "分页查询",httpMethod = "GET")
    public   R findByPage(QueryParam param){

        return   tbItemService.findByPage(param);
    }

    @RequestMapping("/updateItem")//ajax请求  所有请求都支持
    @ResponseBody
    @ApiOperation(value = "修改商品")
    public  R update(TbItem item){

        return  tbItemService.update(item);
    }

    @RequestMapping("/deleteBatch")
    @ResponseBody
    @ApiOperation(value = "批量删除")
    public  R deleteBatch(@RequestParam List<Integer> ids){//ids?

        return  tbItemService.deleteBatch(ids);
    }

    @PostMapping("/deleteBatch1")
    @ResponseBody
    @ApiOperation(value = "批量删除（需要json格式的参数）")
    public  R deleteBatch1(@RequestBody List<Integer> ids){

        return  tbItemService.deleteBatch(ids);
    }

    /**
     * /address?method=delete
     * /address?method=add
     */

    //parameters 简写
    @RequestMapping(value="/address",params = "method=delete")
    public  String deleteAddress(){

        return null;
    }

    @RequestMapping(value = "address",params = "method=add")
    public  String addAddress(){

        return  null;
    }

}
